﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Demos.util;
using mendian;
using Luna小店.DTO;
using Luna小店.UC.面料库存.库存记录.service;
using Luna小店.UC.面料库存.库存记录.model;

namespace Luna小店.UC.面料库存
{
    public partial class Frm面料一览 : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        private List<DTO面料库存> list;
        public Frm面料一览()
        {
            InitializeComponent();
            this.list = 面料记录Service.get面料一览();
            this.gridControl面料一览.DataSource = this.list;
        }

        private void toolStripMenuItem详情_Click(object sender, EventArgs e)
        {
            String id = 
                FunctionHelper.GetgridViewValue(
                    this.gridView面料一览, 
                    this.gridView面料一览.FocusedRowHandle, 
                    "id"
                    );
            //调service通过id取详情
            DTO面料库存 DTO面料库存 = 面料记录Service.get面料详情(id);
            new Frm面料预览(DTO面料库存).ShowDialog();
            //查看详情更改后重新查询
            this.list = 面料记录Service.get面料一览();
            this.gridControl面料一览.DataSource = this.list;
        }

        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SaveFileDialog fileDialog = new SaveFileDialog();
            fileDialog.Title = "导出Excel";
            fileDialog.Filter = "Excel文件(*.xls)|*.xls";
            DialogResult dialogResult = fileDialog.ShowDialog(this);
            if (dialogResult == DialogResult.OK)
            {
                DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
                this.gridControl面料一览.ExportToXls(fileDialog.FileName);
                DevExpress.XtraEditors.XtraMessageBox.Show("保存成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void barButton日记账_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            new Form面料日记账().ShowDialog();
        }

        private void 水洗标详情ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new Frm面料水洗标模板维护(
                FunctionHelper.GetgridViewValue(
                    this.gridView面料一览, 
                    this.gridView面料一览.FocusedRowHandle, 
                    "materialNo"
                    ), 
                FunctionHelper.GetgridViewValue(
                    this.gridView面料一览, 
                    this.gridView面料一览.FocusedRowHandle, 
                    "meterialDesc"
                    ), 
                FunctionHelper.GetgridViewValue(
                    this.gridView面料一览, 
                    this.gridView面料一览.FocusedRowHandle, 
                    "composition"
                    )
                ).ShowDialog();
        }

        private void textBox扫码_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                //循环面料list通过面料号筛选面料
                DTO面料库存 DTO面料库存 = new 面料记录Model().build(this.list, this.textBox扫码.Text.ToString());
                this.textBox扫码.Clear();
                if (null != DTO面料库存)
                {
                    new Frm面料预览(DTO面料库存).ShowDialog();
                }
            }
        }
    }

    

    
}